//
// Created by Martin on 2022/4/8.
//

#ifndef LEETCODE_CPP_LEETCODE429_HPP
#define LEETCODE_CPP_LEETCODE429_HPP

#ifdef __GUNC__
#include <bits/stdc++.h>

#else
#include <vector>
#include <queue>

#endif // __GUNC__

using namespace std;

// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        vector<vector<int>> res;
        if (!root) return res;
        queue<Node*> q;
        q.push(root);

        while (!q.empty()) {
            int size = q.size();
            vector<int> tmp;
            while (size--) {
                Node* p = q.front(); q.pop();
                tmp.push_back(p->val);
                for (int i = 0; i < p->children.size(); ++i) {
                    q.push(p->children[i]);
                }
            }
            res.push_back(tmp);
        }
        return res;
    }
};

#endif //LEETCODE_CPP_LEETCODE429_HPP
